package middleware

import (
	"time"

	"github.com/gin-contrib/cors"
	"github.com/gin-gonic/gin"
)

/*
详细配置信息
https://pkg.go.dev/github.com/gin-contrib/cors#section-readme
https://www.ruanyifeng.com/blog/2016/04/cors.html
*/
// 跨域配置
func Cors() gin.HandlerFunc {
	return cors.New(
		cors.Config{
			AllowAllOrigins: true,
			// AllowOrigins:  []string{"*"},
			AllowMethods:     []string{"GET", "POST", "DELETE", "OPTIONS"},
			AllowHeaders:     []string{"*"},
			ExposeHeaders:    []string{"Content-Length", "Content-Type", "Authorization"},
			AllowCredentials: true,
			// AllowOriginFunc: func(origin string) bool {
			// 	return origin == ""
			// },
			MaxAge: 12 * time.Hour,
		})
	// }
}
